****************************************************************************************************************
**Palmetto Postmortem: Examining the Effects of the South Carolina Voter Identification Statute

**Do file to replicate Tables 4 and 5 and Tables A-D in online Appendix.
**Use: SC.VoterID.dta
 
**Model to Test the Effects of the Voter ID Law (2010 and 2014)

**Data Transformations

gen white=Race
recode white (1=1) (*=0)

gen black=Race
recode black (2=1) (*=0)

gen other=Race
recode other (3 4 5 6=1) (*=0)

gen elec14=Elec
recode elec14 (2010=0) (2014=1)

rename Vote Voted

**Generate Interactive Terms
gen blknoid=black*NoID
gen blk14=black*elec14
gen blknoid14=black*NoID*elec14
gen NoID14=elec14*NoID

********************************************************************************************************
**All Registrants 
**Create 2x2 Tables

tab Voted NoID if Elec==2010, col
tab Voted NoID if Elec==2014, col

tab Voted NoID if Elec==2010 & black==1, col
tab Voted NoID if Elec==2014 & black==1, col

tab Voted NoID if Elec==2010 & white==1, col
tab Voted NoID if Elec==2014 & white==1, col

********************************************************************************************************
**Active Registrants
**Create 2x2 Tables

preserve
**Reduce to Active Registrants
keep if Status==1

tab Voted NoID if Elec==2010, col
tab Voted NoID if Elec==2014, col

tab Voted NoID if Elec==2010 & black==1, col
tab Voted NoID if Elec==2014 & black==1, col

tab Voted NoID if Elec==2010 & white==1, col
tab Voted NoID if Elec==2014 & white==1, col

restore
********************************************************************************************************
**Panel, Active + Inactive Registrants
**Create 2x2 Tables

preserve
**Select Panel
by RegNo, sort: gen panel=1 if _N>1
recode panel (1=1)(.=0)

**Reduce to Panel Only
keep if panel==1

**Panel (Active + Inactive)
**Create 2x2 Tables
tab Voted NoID if Elec==2010, col
tab Voted NoID if Elec==2014, col

tab Voted NoID if Elec==2010 & black==1, col
tab Voted NoID if Elec==2014 & black==1, col

tab Voted NoID if Elec==2010 & white==1, col
tab Voted NoID if Elec==2014 & white==1, col

restore

**********************************************************************************************************
**Panel, Active Registrants
**Create 2x2 Tables

**Reduce to Active Registrants
keep if Status==1

**Select Panel
by RegNo, sort: gen panel=1 if _N>1
recode panel (1=1)(.=0)

**Reduce to Panel Only
keep if panel==1

**Create 2x2 Tables
tab Voted NoID if Elec==2010, col
tab Voted NoID if Elec==2014, col

tab Voted NoID if Elec==2010 & black==1, col
tab Voted NoID if Elec==2014 & black==1, col

tab Voted NoID if Elec==2010 & white==1, col
tab Voted NoID if Elec==2014 & white==1, col

**********************************************************************************************************
**Panel Models
probit Voted NoID elec14 NoID14 

gen keep=1 if e(sample)
drop if keep~=1
save temp, replace

set seed 99
mat b = e(b)
mat V = e(V)

drawnorm x1 x2 x3 cons, ///
mean(b) cov(V) n(1000) clear

sum  

merge using temp

**NoID, 2010
gen noid10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*0 + x3[`i']*0) 
	summarize p_`i', meanonly
	replace noid10=r(mean) in `i'
	
	}
drop p_1-p_1000

**ID, 2010
gen id10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*0 + x3[`i']*0) 
	summarize p_`i', meanonly
	replace id10=r(mean) in `i'
	
	}
drop p_1-p_1000

**NoID, 2014
gen noid14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*1 + x3[`i']*1) 
	summarize p_`i', meanonly
	replace noid14=r(mean) in `i'
	
	}
drop p_1-p_1000

**ID, 2014
gen id14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*1 + x3[`i']*0) 
	summarize p_`i', meanonly
	replace id14=r(mean) in `i'
	
	}
drop p_1-p_1000

gen diff10=id10-noid10
gen diff14=id14-noid14
gen ddiff=diff10-diff14

sum id10 noid10 id14 noid14 diff10 diff14 ddiff
centile id10 noid10 id14 noid14 diff10 diff14 ddiff, centile(2.5 97.5)


drop  x1 x2 x3 cons keep _merge 

**Separate Effects by Race

**Select White and Black Registrants
keep if Race<3

probit Voted NoID black elec14 blknoid blk14 blknoid14 NoID14 

**Probability of Voting by Election, ID, and Race
probit Voted NoID black elec14 blknoid blk14 blknoid14 NoID14 
gen keep=1 if e(sample)
drop if keep~=1
save temp, replace

set seed 99
mat b = e(b)
mat V = e(V)

drawnorm x1 x2 x3 x4 x5 x6 x7 cons, ///
mean(b) cov(V) n(1000) clear

sum  

merge using temp

**White NoID, 2010
gen wnoid10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*0 + x3[`i']*0 + ///
	x4[`i']*0 + x5[`i']*0 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace wnoid10=r(mean) in `i'
	
	}
drop p_1-p_1000

**White ID, 2010
gen wid10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*0 + x3[`i']*0 + ///
	x4[`i']*0 + x5[`i']*0 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace wid10=r(mean) in `i'
	
	}
drop p_1-p_1000

**White NoID, 2014
gen wnoid14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*0 + x3[`i']*1 + ///
	x4[`i']*0 + x5[`i']*0 + x6[`i']*0 +x7[`i']*1) 
	summarize p_`i', meanonly
	replace wnoid14=r(mean) in `i'
	
	}
drop p_1-p_1000

**White ID, 2014
gen wid14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*0 + x3[`i']*1 + ///
	x4[`i']*0 + x5[`i']*0 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace wid14=r(mean) in `i'
	
	}
drop p_1-p_1000



**Black NoID, 2010
gen bnoid10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*1 + x3[`i']*0 + ///
	x4[`i']*1 + x5[`i']*0 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace bnoid10=r(mean) in `i'
	
	}
drop p_1-p_1000

**Black ID, 2010
gen bid10=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*1 + x3[`i']*0 + ///
	x4[`i']*0 + x5[`i']*0 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace bid10=r(mean) in `i'
	
	}
drop p_1-p_1000

**Black NoID, 2014
gen bnoid14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*1 + x2[`i']*1 + x3[`i']*1 + ///
	x4[`i']*1 + x5[`i']*1 + x6[`i']*1 +x7[`i']*1) 
	summarize p_`i', meanonly
	replace bnoid14=r(mean) in `i'
	
	}
drop p_1-p_1000

**Black ID, 2014
gen bid14=.
quietly forvalues i = 1/1000 {
	gen p_`i'=normal(cons[`i'] + x1[`i']*0 + x2[`i']*1 + x3[`i']*1 + ///
	x4[`i']*0 + x5[`i']*1 + x6[`i']*0 +x7[`i']*0) 
	summarize p_`i', meanonly
	replace bid14=r(mean) in `i'
	
	}
drop p_1-p_1000

gen wdiff10=wid10-wnoid10
gen wdiff14=wid14-wnoid14
gen wdiff=wdiff10-wdiff14
gen bdiff10=bid10-bnoid10
gen bdiff14=bid14-bnoid14
gen bdiff=bdiff10-bdiff14

gen racediff=wdiff-bdiff

sum wnoid10 wid10 wnoid14 wid14 bnoid10 bid10 bnoid14 bid14
centile wnoid10 wid10 wnoid14 wid14 bnoid10 bid10 bnoid14 bid14, centile(2.5 97.5)

sum wdiff10 wdiff14 wdiff bdiff10 bdiff14 bdiff racediff
centile wdiff10 wdiff14 wdiff bdiff10 bdiff14 bdiff racediff, centile(2.5 97.5)

drop  x1 x2 x3 x4 x5 x6 x7 cons keep _merge 

restore

